package com.industrial.white.controller;


import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.white.domain.EmContingencyManagement;
import com.industrial.white.service.IEmContingencyManagementService;
import com.industrial.white.vo.EmContingencyManagementVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急管理Controller
 * 
 * @author ZHOU_S
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/management")
public class EmContingencyManagementController extends BaseController
{
    @Autowired
    private IEmContingencyManagementService emContingencyManagementService;




    @GetMapping("/groupList")
    public TableDataInfo groupList(EmContingencyManagement emContingencyManagement)
    {
        startPage();
        List<EmContingencyManagementVo> list = emContingencyManagementService.groupList(emContingencyManagement);
        return getDataTable(list);
    }
    /**
     * 查询应急管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EmContingencyManagement emContingencyManagement)
    {
        List<EmContingencyManagement> list = emContingencyManagementService.selectEmContingencyManagementList(emContingencyManagement);

        return getDataTable(list);
    }

    /**
     * 导出应急管理列表
     */
    @Log(title = "应急管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmContingencyManagement emContingencyManagement)
    {
        List<EmContingencyManagement> list = emContingencyManagementService.selectEmContingencyManagementList(emContingencyManagement);
        ExcelUtil<EmContingencyManagement> util = new ExcelUtil<EmContingencyManagement>(EmContingencyManagement.class);
        util.exportExcel(response, list, "应急管理数据");
    }

    /**
     * 获取应急管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(emContingencyManagementService.selectEmContingencyManagementByBaseId(baseId));
    }

    /**
     * 新增应急管理
     */
//    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "应急管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmContingencyManagement emContingencyManagement)
    {
        int flag=emContingencyManagementService.insertEmContingencyManagement(emContingencyManagement);
        if(flag>0){
            return AjaxResult.success("添加成功!");
        }else{
            return AjaxResult.warn("今日应急数据已上报！");
        }
    }

    /**
     * 修改应急管理
     */
//    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "应急管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmContingencyManagement emContingencyManagement)
    {
        return toAjax(emContingencyManagementService.updateEmContingencyManagement(emContingencyManagement));
    }

    /**
     * 删除应急管理
     */
//    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "应急管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(emContingencyManagementService.deleteEmContingencyManagementByBaseIds(baseIds));
    }

    @Log(title = "数据报送", businessType = BusinessType.UPDATE)
    @PutMapping("editUpdateIds")
    public AjaxResult editUpdateIds(@RequestBody EmContingencyManagement[] emContingencyManagements)
    {

        if(emContingencyManagements.length>0){
            return toAjax(emContingencyManagementService.updateByBaseIds(emContingencyManagements));
        }else{
            return AjaxResult.warn("无此操作权限！");
        }
    }

}
